<?php
session_start();
require "../../../global.php";//$dirname."/".
require RootDir."/"."inc/Function.Libary.php";
require RootDir."/"."inc/config.php";
require RootDir."/"."inc/Uifunction.php";
require RootDir."/".$SystemConest[1]."/system/Config.php";
require RootDir."/".$SystemConest[1]."/UIFunction/adminClass.php";
require RootDir."/".$SystemConest[1]."/system/menusys/function.php";
require RootDir."/".$SystemConest[1]."/system/classsys/function.php";
require RootDir."/".$SystemConest[1]."/system/log/addlog.php";

FunPostGetFilter(2);//过滤非法信息
$mydb=new YYBDB();

$PMID=$_REQUEST["PMID"];

$TableName=reTableName($mydb,$MenuId);
CheckRule($MenuId,$mydb,$TableName,"Update");//检查登陆权限
$FormConfig1=GetFormConfig($mydb,$MenuId);

$sql="select ".$SystemTablename[2]."10 from ".DQ.$SystemTablename[2]." where ".$SystemTablename[2]."0=".$MenuId;
$rsc=$mydb->db_query($sql);
if($rs=$mydb->db_fetch_array($rsc)){
	$Configother=explode(",",$rs[$SystemTablename[2]."10"]);
	
}


if(strlen($FormConfig1)<1) die;
$ArrFormConfig=explode(",",$FormConfig1);
$configarr=array();
$i=0;
foreach($ArrFormConfig as $k=>$v)
{
	$arr=explode("|",$v);
	$configarr[$i]=$arr;
	$i++;
}
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>保存修改</title>
<link href="../../Inc/Css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?


$ID=$_REQUEST["ID"];
if(strlen($MenuId)<1)
{
	$MenuId=-1;
}

echo CurrPosition((int)($MenuId),$mydb);

$FieldCount=GetTableFieldCount($mydb,$TableName);

$myFields=array();

for($i=1;$i<$FieldCount;$i++){
	if($_REQUEST["FieldName_".$i."_class"] =="" && $_REQUEST["FieldName_".$i] !=""){
		if($_REQUEST["FieldName_".$i."_Min"]!=""){
			$temp="";
			$temp=$_REQUEST["st".$_REQUEST["FieldName_".$i."_Min"]];//当是无限级下拉菜单时
			if($temp!=""){
				$myFields[$i]=$temp;
			}
			else{
				$myFields[$i]=$_REQUEST["FieldName_".$i."_Min"];
			}
		}
		else{
			$tempqwe=$_REQUEST["FieldName_".$i.""];
			
			if(is_array($tempqwe)){
				foreach($tempqwe as $t){
					$myFields[$i]=$myFields[$i].$t.",";
				}
				$myFields[$i]=",".$myFields[$i];
			}
			else{
				$myFields[$i]=$tempqwe;
			}
			//当是数字型时，转化为数字
			if($configarr[$i]["1"]=="8"){
				$myFields[$i]=strtotime($myFields[$i]);
			}
			unset($tempqwe);
		}
	}
	else{
				$temp=$_REQUEST["st".$_REQUEST["FieldName_".$i.""]];//当是无限级下拉菜单时
				if($temp!=""){
					$myFields[$i]=$temp;
				}
				else{
				if($_REQUEST["FieldName_".$i."_class"]!="")
				{
					$myFields[$i]=$_REQUEST["FieldName_".$i."_class"];
				}else{
					$myFields[$i]=$_REQUEST["FieldName_".$i.""];
				}
					
				}
	}
}

$myFields[0]=$ID;
$mydb->TableName=$TableName;
$mydb->ArrFields=$myFields;
$mydb->Update();

//======================================若有模板选项，生成静态文件件
$temp1="生成选项没有执行";

if($_REQUEST["moban"]!="" and $_REQUEST["JingTaihtml"]!="" and strstr($_REQUEST[$_REQUEST["JingTaihtml"]],"."))
{
	require_once(RootDir."/"."inc/ActionFile.Class.php");
	$myFile=new ActionFile();
	if($myFile->CreateAnyPageToPage("http://".$_SERVER['HTTP_HOST']."/".Q.$_REQUEST["moban"]."".$ID,RootDir.$_REQUEST[$_REQUEST["JingTaihtml"]]))
	{
		$temp1=",生成静态文件成功!";
	}
	else
	{
		$temp1=",生成静态文件失败!";
	}
	
}
//=================================================================

$turngotourl=$Configother[6];
if(strlen($turngotourl)>7){
	$turngotourl=str_replace("{MenuId}",$MenuId,$turngotourl);
	$turngotourl=str_replace("{PMID}",$PMID,$turngotourl);
	$turngotourl=str_replace("@",$ID,$turngotourl);
}
else{
	$turngotourl="/".$SystemConest[1]."/system/".$TableName."/Index.php?MenuId=$MenuId&PMID=". $_REQUEST["PMID"]."&CurrPage=" .$_REQUEST["CurrPage"].""	;
}
if($mydb->Returns >0)
{
		addlog($mydb,$_SESSION["Login"][1],"更新".$TableName."记录id".$ID);
		MessgBox("/".$SystemConest[1]."/Iamges/Right.jpg","数据保存成功！$temp1",$turngotourl) ;
}
else
{
	MessgBox("/".$SystemConest[1]."/Iamges/Error.jpg","数据保存失败！$temp1",$turngotourl) ;
}

?>
</body>
</html>
